package yjl.spec.edu.week11_class023;


import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.List;

import yjl.spec.edu.week11_class023.R;

public class ThreeAdapter extends RecyclerView.Adapter<ThreeAdapter.ViewHolder>{

    private List<Three> mthreeList;

    static class ViewHolder extends RecyclerView.ViewHolder {
        View threeView;
        ImageView threeImage;
        TextView threeName;

        public ViewHolder(View view) {
            super(view);
            threeView = view;
            threeImage = (ImageView) view.findViewById(R.id.imageView19);
            threeName = (TextView) view.findViewById(R.id.textView10);
        }
    }

    public ThreeAdapter(List<Three> threeList) {
        mthreeList = threeList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.three_item, parent, false);
        final ViewHolder holder = new ViewHolder(view);
        holder.threeView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int position = holder.getAdapterPosition();
                Three thre_img = mthreeList.get(position);
                Toast.makeText(v.getContext(), "you clicked view " + thre_img.getName(), Toast.LENGTH_SHORT).show();
            }
        });
        holder.threeView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int position = holder.getAdapterPosition();
                Three thre_img = mthreeList.get(position);
                Toast.makeText(v.getContext(), "you clicked image " + thre_img.getName(), Toast.LENGTH_SHORT).show();
            }
        });
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Three three = mthreeList.get(position);
        holder.threeImage.setImageResource(three.getImageId());
        holder.threeName.setText(three.getName());
    }

    @Override
    public int getItemCount() {
        return mthreeList.size();
    }

}
